define(function(require, exports, module) {
	require('./css/style.css')

	function onload() {
		var api = require('./config.json');
		return {
			components: {},
			template: require('./Widget.html'),
			props: {
				houseId: {
					type: String,
					default: ''
				},
				visible: {
					type: Boolean,
					default: false
				}
			},
			data() {
				return {
					peopleList: [],
					idCard: undefined,
					loading: false,
					viewValue: '',
					viewModel: ''
				}
			},
			watch: {
				visible: {
					handler(newName, oldName) {
						this.viewModel = ''
					},
					// 开启深度监听
					deep: true
				}
			},
			methods: {
				// 下拉框关闭的时候清空数据
				visibleChange(show) {
					if (!show) {
						this.peopleList = []
					}
				},
				// 搜索身份证后六位
				handleSearchPeople(query) {
					if (query && query.length === 8) {
						this.loading = true;
						setTimeout(() => {
							$.get(alluse.bigcenter + api.搜索身份证后六位 + query, res => {
								if (res.code === 200) {
									this.loading = false;
									this.peopleList = res.data
									this.viewValue = query
								} else {
									this.msgError(res.msg)
								}
							});
						}, 200);
					} else {
						this.peopleList = [];
					}
				},
				// 搜索
				handleSearch(sfhm) {
					this.viewModel = this.viewValue
					this.peopleList = [{
						sfhm: this.viewValue,
						xm: this.viewValue
					}]
					if (this.houseId) {
						$.get(alluse.bigcenter + api.搜索整户引入完整的身份证 + sfhm + '/' + this.houseId, res => {
							if (res.code === 200) {
								this.$emit("result", res.data);
							} else {
								this.msgError('没有找到与该人员相关的信息')
							}
						});
					} else {
						$.ajax({
							url: alluse.bigcenter + api.搜索完整的身份证,
							type: 'GET',
							dataType: 'json',
							contentType: 'application/json',
							data: {
								sfhm
							},
							success: (res) => {
								if (res.code === 200) {
									this.$emit("result", res.data);
								} else {
									this.msgError(res.msg)
								}
							}
						});
					}

				}
			},
		}
	}

	module.exports = {
		onload
	};
});
